package com.hiwhitley.easy.day14;

import com.hiwhitley.base.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hiwhitley on 2016/8/18.
 */
public class LevelOrder {
    public List<List<Integer>> levelOrder(TreeNode root) {
        List<List<Integer>> result = new ArrayList<>();
        helper(root, 0, result);
        return result;
    }

    public void helper(TreeNode root, int depth, List<List<Integer>> result) {
        if(root == null) return;
        if(result.size() <= depth) result.add(new ArrayList<>());
        result.get(depth).add(root.val);
        helper(root.left, depth+1, result);
        helper(root.right, depth+1, result);
    }
}
